Saturday, November 26, 2016

Arduino Model Railroad Scale Speedometer - Finished

We finally finished the Scale Speedometer Project, and are heading off to the club to install it. We used the Adafruit I2C 7 Segment backpack, a Arduino Nano clone, and two IR transceivers, for  total project cost of around $20. The code below is fully functional, all you need to do is adjust your scale, and distance between the sensors. Make sure your sensors do not extend above the height of the rails, or couplers could catch on them. I used a dremel to route out the holes, and superglue to fix them in place, but superglue leaves a white residue, so you may want to try a different adhesive. Watch the video!

Arduino Nano Clone
7 Segment BackPack
IR sensors

Use the Adafruit Tutorial to assemble and connect your 7 segment backpack. Use the IR Sensor Tutorial to connect the IR sensors.

Update: Decreasing the resistance of the IR LED resistor (try 150 Ohm) or increasing the resistance of the pullup resistor on the photo-transistor (try 100k) can make the circuit more sensitive (up to 15mm depending on reflectance of car bottom), especially for larger scales with larger gaps. Do not burn out the IR LED with too low of a resistance (no less than 68 Ohm, 1/2w at 5v input).

#include  "Wire.h"
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

Adafruit_7segment matrix = Adafruit_7segment();

//user variables
float distance = 24; //inches between sensors
int scale=87;

int sensor1 = 4;
int sensor2 = 5;
bool s1Covered;
bool s2Covered;
float start, finish, elapsed, miles, hours, mph, scaleMPH;

int started=0, finished=0;
int scale=87;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
  matrix.begin(0x70);

}

void loop() {
  // put your main code here, to run repeatedly:
  //Serial.println("Ready ....");
  matrix.print(0.0);
  matrix.writeDisplay();
    //finished=0;
    s1Covered=digitalRead(sensor1);
    if (s1Covered==0 && started==0){
      start=millis();
      started=1;
      Serial.println("Started");
   
    }
    s2Covered=digitalRead(sensor2);

    if (s2Covered==0 && started==1){
      finish=millis();
      finished=1;
      Serial.println("Finished");
   
  elapsed = finish-start; // millis

  elapsed = elapsed /1000; // seconds
  Serial.print("Seconds: ");
  Serial.println(elapsed);
  miles = distance / 63360; // miles
  hours = elapsed / 3600; // hours
  mph = miles / hours;
  scaleMPH = mph * scale;
  Serial.print("Scale MPH: ");
  Serial.println(scaleMPH);
 
  // print a floating point
  matrix.print(scaleMPH);
  matrix.writeDisplay();
  delay(5000);

  started=0;
  finished=0;
    }
  }


Friday, November 18, 2016

Functional TRS-80 Model 1 on Windows 10?


Ok, what does this have to do with Arduino or Raspberry Pi? Well, I am working on a couple of Pi emulating antique computer projects, and said, let's try this! I could use some financial help with a few projects we are working on, so use the "Donate" button found on this page, and I'll send you a zip file with a working TRS-80 Model 1 emulator (ROM included). Just unzip and run an old friend ....

Tuesday, November 15, 2016

Arduino Scale Speedometer Part 3 - Port Expander

The three 7 segment LED's from part 2 require 24 i/o pins on the Arduino. We can use port expanders to limit that to 2 pins, the I2c connections. Each MCP23017 chip supports 16 i/o pins, so two chips will do, and still only use the two lines on the Arduino, as they are addressable. In our previous two MCP23017 posts we show how to connect and address the MCP23017 chips and provide a link to the datasheet.

1st Digit - Chip 1 Port A Connections:
GPA7 -> A7
GPA6 -> B6
GPA5 -> C4
GPA4 -> D2
GPA3 -> E1
GPA2 -> F9
GPA1 -> G10
GPA0 -> DP5

2nd Digit - Chip 1 Port B Connections:
GPB7 -> A7
GPB6 -> B6
GPB5 -> C4
GPB4 -> D2
GPB3 -> E1
GPB2 -> F9
GPB1 -> G10
GPB0 -> DP5

3rd Digit - Chip 2 Port A Connections:
GPA7 -> A7
GPA6 -> B6
GPA5 -> C4
GPA4 -> D2
GPA3 -> E1
GPA2 -> F9
GPA1 -> G10
GPA0 -> DP5



To send the speed determined in part 1 to the 3 digit display, we need to break up the number into 3 separate numbers, the hundreds, tens, and ones position. This is done with a simple calculation:

first=number/100;
second=number%100/10;
third=number%10;

Then in a case statement you can send the correct code to each chip:

switch (var) {
    case 0:
      Wire.write(244); //11110100
      break;
    case 1:
      Wire.write(96); //01100000
      break;
    case 2:
      Wire.write(218); //11011010
      break;
    case 3:
      Wire.write(242); //11110010
      break;
    case 4:
      Wire.write(102); //01100110
      break;
    case 5:
      Wire.write(182); //10110110
      break;
    case 6:
      Wire.write(190); //10111110
      break;
    case 7:
      Wire.write(224); //11100000
      break;
    case 8:
      Wire.write(254); //11111110
      break;
    case 9:
      Wire.write(230); //11100110
      break;
    case DP:
      Wire.write(1); //00000001
      break;
    default:
      // if nothing else matches, do the default
      // default is optional
    break;
  }

Now, if all this seems very complicated, and the 24 wires from the 3 digits to the two MCP23017 chips seems like spaghetti, you are right, and we have chosen to go a different path. The Adafruit I2C 4 digit display. More on that tomorrow .....

Monday, November 14, 2016

Arduino Scale Speedometer Part 2 - 7 Segment LED's

In part two (see part 1 for the train detection circuit) we are addressing the three 7 segment displays. We are using Common Anode displays, so we send a low to each segment to light them up. Use whatever you have available, and use the data sheet for your displays and map accordingly.


 This image shows each segment, and assigns a letter to each, to help with the wiring.






The next image shows the pin numbers and positions looking at the face of the display.

Now we show which segment is assigned to which pin, and the polarity of the pins. Since we are using Common Anode, the LED symbols point down,or away from the common positive (5v) signal (pins 3 & 8). A LOW is sent to each pin to light up the associated segment. If you are using Common Cathode, then the diodes would point up, 3 & 8 would connect to ground, and a HIGH would be sent to each segment to light them.

As is the case with all LED's, a current limiting resistor is needed to prevent the LED from burning out. The one you pick is dependent upon your source voltage, and the LED. We are using 400 Ohm resistors for this project.

The next post will address using a I2C port expander to free up the 24 pins the display uses.

Sunday, November 6, 2016

Arduino Model Railroading - Scale Speedometer

The guys at the Model Railroad Club wanted a scale speedometer displaying the scale speed of the train as it passes a point on the layout. I'm using two IR transceivers connected to an arduino to detect the time it takes to pass between 2 points, and then displaying the scale speed.

Currently we are using the Serial Monitor, but Part 2 will be about the 3 seven segment display and I2C port expander used to drive them.



Wiring:
The circuit diagram is the same as the one we posted here, but just doubled.

Code:

int sensor1 = 4;
int sensor2 = 5;
bool s1Covered;
bool s2Covered;
float start, finish, elapsed, miles, hours, mph, scaleMPH;
float distance = 24; //inches between sensors
int started=0, finished=0;
int scale=87;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

    //finished=0;
    s1Covered=digitalRead(sensor1);
    if (s1Covered==0 && started==0){
      start=millis();
      started=1;
      Serial.println("Started");
    }
    s2Covered=digitalRead(sensor2);

    if (s2Covered==0 && started==1){
      finish=millis();
      finished=1;
      Serial.println("Finished");
   
  elapsed = finish-start; // millis

  elapsed = elapsed /1000; // seconds
  Serial.print("Seconds: ");
  Serial.println(elapsed);
  miles = distance / 63360; // miles
  hours = elapsed / 3600; // hours
  mph = miles / hours;
  scaleMPH = mph * scale;
  Serial.print("Scale MPH: ");
  Serial.println(scaleMPH);
  started=0;
  finished=0;
    }
  }




Saturday, November 5, 2016

Arduino Model Railroading - Simulated Flickering Fire

Another cool exhibit on your model railroad is flickering firelight. Whether it's a hobo campfire, or a burning building, this adds to the layout's realism. A Arduino, 3 130 ohm resistors, two yellow LEDs, one red LED, and you have a fire. Add a locomotive smoke unit for additional realism. This project is provided by Mike McRoberts.


Just connect a wire from pin 9 to the resistor, from the resistor to the long leg (+) of your LED, and the short leg to Ground. Repeat for pins 10 & 11. We put the red LED on pin 10, and the 2 yellows on 9 & 11.
Code:

// LED Fire Effect

int ledPin1 = 10;
int ledPin2 = 9;
int ledPin3 = 11;

void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}

void loop() {
analogWrite(ledPin1, random(120)+135);
analogWrite(ledPin2, random(120)+135);
analogWrite(ledPin3, random(120)+135);
delay(random(100));
}


Arduino Model Railroading - Arc Welder Flash

The guys at the Charleston Model Railroad Club asked for a simulated flash of an arc welder. A $4 (was $2.50, price went up since we purchased) arduino nano clone, a 130 ohm resistor, and a white LED later, they have their arc welder. This is a fun and inexpensive project that adds to the realism of your layout!

Project inspired by the work at http://mrrwa.org/wp-content/uploads/2011/07/ModelRailroadingWithArduino.pdf

Just connect a wire from pin 9 to the resistor, from the resistor to the long leg (+) of your LED, and the short leg to Ground.


Code:

int ledPin = 9; // LED connected to digital pin 9
int i;
int count;

void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop()
{
count=random(10,60);
for (i=0;i{
digitalWrite(ledPin, HIGH); // set the LED on
delay(random(60));
digitalWrite(ledPin, LOW); // set the LED off
delay(random(200));
}
delay(random(800,2000)); // wait a random bit of time
}







Monday, October 3, 2016

New Book: The Citizen Scientist's Guide to using the Arduino & Raspberry Pi

Our new book is online, a chapter at a time. We have a dozen chapters in various stages of proofing and testing, and have the first 3 uploaded and available at http://arduinotronics.blogspot.com/p/citizen-science-book.html, so check them out, and leave us feedback on thoughts, problems, ideas, etc.

Posted chapters will be improved and added to and new chapters added, so keep coming back for more.

Saturday, October 1, 2016

Two Arduinos Become One

It was announced today that Arduino LLC (aka Arduino.cc) and Arduino srl (aka Arduino.org) will rejoin to become one Company.
Massimo Banzi and Federico Musto took the stage at the New York Maker Faire to announce the good news, and the Arduino team demonstrated its products.
At the end of 2016, the newly created “Arduino Holding” will become the single point of contact for the wholesale distribution of all current and future products, and will continue to bring tremendous innovations to the market.
In addition, Arduino will form a not-for-profit “Arduino Foundation” responsible for maintaining the open source Arduino desktop IDE, and continue to foster the open source movement by providing support for a variety of scholarships, community and developer initiatives.
Massimo Banzi, Co-Founder of Arduino LLC, said, “Today is one of the best days in Arduino history. This allows us to start a new course for Arduino made of constructive dialogue and non-disruptive innovation in the Education, Makers and IoT fields. The Arduino Foundation will allow us to champion the core values of the Arduino Community within the open source ecosystem and to make our commitment to open source stronger than ever. This is really a new beginning for Arduino!”
“Of course, we are thrilled to resolve the issues that have taken place over the past couple of years, and the team is working together to continue to offer the best open hardware and software,” said Federico Musto, CEO & President of Arduino Srl. “We know how passionate our partners and developers are about Arduino, and the growth and loyalty has been astonishing. Arduino developers will continue to see amazing technical developments including NFC, BLE, voice controls, and more, to fuel the IoT growth and other innovations.”

Thursday, July 21, 2016

Controlling AC Loads with a MOSFET

In past articles I have shown how to control dc loads with a logic level MOSFET, but did you know you can control AC loads as well, just indirectly? The attached image shows the circuit diagram, and the MOSFET code and wiring is the same as our DC Projects. Can you figure out how this works?  For details, see http://tahmidmc.blogspot.com/2012/11/controlling-ac-load-with-mosfet.html

Use an IRL series n-channel MOSFET like the IRL520 or IRL540 that are designed to be driven at 5v.

Tuesday, July 5, 2016

Whole House Energy Monitor - Part 2

Testing the first batch of WHEM boards, I discovered a mistake in one of the traces. Out came the rotary tool, and I ground out two trace connections, and soldered in 2 jumpers. This will be corrected on the REV 2 boards. Two tools I would not be without are my WEN Rotary Tool and my Board Holder.

The parts call out is:

R1 - 100k Ohm
R2, R3, R4, R6, R7, R9, R10 - 10k Ohm
R5, R8 - 44.2 Ohm
C1, C2, C3 - 10uf 16v

I_Sense_1 & I_Sense_2 - SCT016 120a / 40ma (one for each leg of your breaker box)
V_Sense - 9vac transformer

Order boards, parts, and finished assembly at http://arduinotronics.blogspot.com/2016/06/whole-house-energy-monitor.html




R4 isolated and jumpered


Correct V_Sense Schematic - R4 (bottom 10k)

Parts Kit



Tuesday, June 14, 2016

Whole House Energy Monitor

Our board design for the whole house energy monitor just went to production, boards should be here in about 2 weeks (See update). We made this a through-hole design for ease of assembly (kit version) and modification. Complete kit consists of the circuit board, 2 current transducers, 1 drop down transformer, screw terminals, and a handful of resistors and capacitors. All that is needed is a Arduino and a Ethernet or WiFi board to transmit readings (amps and volts recorded, watts and watt hours are calculated) to our hosted (or your own) database so that the user can log in and see their daily, weekly, monthly and yearly consumption. We have discussed how to monitor whole house power and energy previously at http://arduinotronics.blogspot.com/2016/02/ac-current-monitoring-current.html, and sent out a couple of hand soldered perf board prototypes, but now have a professional solution which will be available in bareboard, kit, and finished versions. The data is stored and displayed on a hosted or optionally, a local server (Raspberry Pi). We have also discussed building your own web / database part of this solution at http://arduinotronics.blogspot.com/2015/12/building-iot-server.html

Thanks to PCBCart.com and Scott Quirk for making this project possible!


On the parts kit, let us know if you have a 5v or 3,3v controller. 
You supply the Arduino and ethernet shield.






Options

Sunday, April 10, 2016

The Simple Way to Create a Raspberry Pi Boot SD Card

You probably have read instructions about burning images and special software needed to create the sd card to boot your Raspberry Pi, but none of that is needed. Grab a 8GB+ SD Card, and follow along with this simple, easy tutorial:

On your Windows, Mac, or Linux PC, go to https://www.raspberrypi.org/downloads/noobs/ and download the NOOBS Offline and network install zip file. It's about 1 GB in size, so this could take a bit. Go make a cup of coffee while you wait!

After downloading, extract the zip file to your new or freshly formatted (FAT32) sd card. Do not create a new folder.

Once finished, insert the sd card into your Raspberry Pi, connect power, HDMI video, (optional network cable) and keyboard/mouse and you are off and running. Just follow the Pi's onscreen install instructions.

Accessories we use and recommend are:

Logitech Wireless Keyboard / Mouse Combo 
Edimax Wifi USB
2.5 amp USB Power supply
16GB SD Card
HDMI Cable

Tuesday, March 29, 2016

The Best Dang Raspberry Pi Tutorial!

I've been a big fan of Simon Monk for quite a while. Whether it's his Arduino evil genius books, or his electronics "courses", It's always educational and fun to read. This time, Simon takes us on a updated journey through the Raspberry Pi. From explanation of  the hardware and software, through setup, to programming in Python, creating user interfaces, and reading and controlling electronics through the I/O pins, this book covers it all with an easy to understand helpful tone. Perfect for beginners, but not boring for those of us with prior experience.

Programming the Raspberry Pi, Second Edition: Getting Started with Python


As usual, all the code mentioned in the book is available for download at his website, and new projects continue to be posted on his blog. 

About the Author

Dr. Simon Monk has a bachelor’s degree in cybernetics and computer science and a Ph.D. in software engineering. He is now a full-time writer and has authored numerous books, including Programming Arduino, 30 Arduino Projects for the Evil Genius, Hacking Electronics, and Fritzing for Inventors. Dr. Monk also runs the website monkmakes.com, which features his own products.

Sunday, March 6, 2016

Speaking Appliances for the Visually Impaired

We are working with an organization that provides adapters and converted equipment to announce status messages by speech instead of visually. We have speech enabled shop measuring equipment like calipers, micrometers and dial indicators, weather stations, and thermostats, and are working of speech enabled appliances, motion sensors, and other common gadgets. To help fund this endeavor, we have reduced the prices of all our ebooks at http://green-trust.org/products/ to $10 each.

To see a bit of what we are working on, see: