Tuesday, November 21, 2017

Arduino and Raspberry Pi Holder

When you are building circuits and programming your microcontroller, you probably have it sitting on a table, wires going everywhere, and possibly shorting the bottom pins on clipped wire pieces, tools, and other obstructions. It can be a challenge to keep everything tidy and organized, which can cause trouble shooting issues. I'm looking forward to my new organizer coming this week, and I will post video of it in use. It allows me to keep a Raspberry Pi, Arduino, and a breadboard stable and secure. Projects have a higher possibility of working the first time, as I can see better if wires are going where they are supposed to, and have not pulled loose!

Arduino / Pi / Breadboard Base

Wednesday, November 15, 2017

Model Railroad DCC Control - JMRI / Raspberry PI

For those who want to control their DCC Model Railroad with their cell phones or tablets (pretty much any Android (Engine Driver) or IOS (WiThrottle) device), There is a Raspberry Pi image already built. Copy it to a sdcard, insert into your Raspberry Pi, and you are pretty much set to go!

Once you've assembled the hardware and installed the image, connect your RPi to your layout via PR3, LocoBuffer-USB, NCE Serial, NCE USB, SPROG or DCC++, and plug in the RPi's power adapter.  You should see some LEDs on the RPi begin to blink, and shortly, using your wifi-capable phone, you'll see a WiFi network named "RPi-JMRI".  Select it and enter "rpI-jmri" when prompted for the key (note that 3rd character is a capital "eye").  Open EngineDriver on your phone, and you should have an available connection under Discovered Servers called "RPi-JMRI".  (Similar with WiThrottle on iPhone).  Enter loco address and run trains!

Tuesday, November 14, 2017

Breadboard Friendly ESP8266-01 / nRF24L01+

The cheapest WiFi modules on the market (around $3 each) are the ESP8266-01 boards, which are WiFi enabled microcontrollers in their own right (with limited I/O), or they can be used with an Arduino as the WiFi interface. However, they have a funky 2x4 header that is not breadboard friendly.

Here is one possible solution. A inexpensive 2x4 to breadboard converter with a 2x4 socket on top and headers on bottom that match up nicely with a breadboard. It not only works with the ESP8266-01, but also works with the nRF24L01+ RF modules as well.

Now it's very easy to experiment with these handy modules. If you need a 5v to 3.3v regulator and level shifting for your ESP8266-01, check out these converters!

More ESP8266 Fun!

We have shown how to use the ESP8266 to collect sensor data, and send it to a database (client mode), but you can also use the ESP8266 as a webserver, displaying a web page and showing status or accepting input (server mode). In fact, it can be a server and a client at the same time. The following code runs a webserver on the esp8266, providing input fields to instruct the esp8266 to perform an action, and then POSTs that set of actions to the database. You could also read a sensor to verify that the actions were actually performed.

Code



 

Tuesday, September 26, 2017

Calculate Daylight Savings Time Date

The web based apps I write often have informative messages for the users, and one request was a reminder to change the clocks for Daylight Savings Time. Since it's not the same date each year, but is always the Second Sunday of March and the First Sunday of November, I needed to be able to get a date for those days. It's fairly easy in PHP, as you can see below.



$year = date('Y');
$spring = date('m-d-Y 02:00:00 A', 
strtotime('Second Sunday Of March '.$year)); $fall = date('m-d-Y 02:00:00 A',
strtotime('First Sunday Of November '.$year)); echo 'Spring: ' . $spring; echo 'Fall: ' . $fall;
Here is the quiz of the day:

How would you accomplish this on the Arduino?

Reference:

Arduino Time Libraries

Arduino DST Solution

Friday, August 25, 2017

Arduino / Relay Interference

Symptom: 

You have a relay connected to your Arduino, and after a while your Arduino stops running. That's not supposed to happen, these things loop forever, right?

It's a common issue when running inductive loads from a Arduino controlled relay. Many folks think it's a voltage problem and try throwing capacitors on the relay supply, or using a opto isolated relay (separate power and ground). These solutions may work, but more often than not, they don't.

Cause: 

So what is causing the problem? It's EMI!
The back EMF from an inductive load causes the relay contacts to act like a spark gap transmitter, scrambling the processor. The Atmel chips are very susceptible to RF.

Not to worry, it's not permanent, it clears when you cycle power.

How did we discover this and how do you keep it from happening?

We have a project where a Nano and a common relay board are installed in a small case. When all the parts are assembled on the bench, it works fine. When crammed together in the box, it works for a while, then freezes. But only with a inductive load attached to the relay. With no load, or a resistive load, it runs forever (well, 3 days or more, forever was too long a test period). We have tested this six ways to sunday with a variety of Arduino and Arduino clones.

Solution:

Installing snubbing diodes on relay coils and motors (the common solution) can be difficult (they don't work on ac devices) or void a warranty on many household appliances.

I series connected a resistor and a capacitor together, and connected those across the Arduino relay contacts (as close to the relay contacts as you can get). This quenches the back EMF, and prevents the Arduino from locking up. There you go, a $0.30 solution to a nagging problem.

Make sure your capacitor is rated for the voltage you expect to see. I used a .1 uF 50v Tantalum, and a 100 Ohm 1/4w resistor on a 26v circuit. My load was another relay. In another application, the load was a 120v motor, so the cap was 150v.


Tuesday, August 22, 2017

2 Channel IR Interface

Recently we produced a 6 Channel IR interface for IR transceivers like the TCRT5000 pairs. Lots of Model Railroading and other object detection applications. Now we have the less expensive 2 channel version available. Same code, same components, just less of them! - $30 + S&H


Harbor Freight Caliper Interface

Did you know the inexpensive Pittsburgh / Chicago Tool / Harbor Freight Calipers (4 pin dataport under battery cover) have a digital interface? We can read that interface with an Arduino, just like we do with the Mitutoyo / Igaging calipers and micrometers. The electrical interface is different, as is the data stream. Now, thanks to the hard work and experimentation of the folks at Arduinotronics, you can integrate measurement into your projects. I'll be posting video, code and schematic shortly, but get your board order in now so you can get started! $15 + S&H






Friday, August 11, 2017

Setting up a Mosquitto MQTT IOT Broker

Ever want to view / control devices at home while on the road?

As part of our IoT initiative, I have set up a broker based on Mosquitto. Mosquitto uses MQTT, a publish and subscribe mechanism that avoids the necessity of special router configuration on your home network. A sensor node (arduino with ethernet or wifi, esp8266, etc.) publishes data to the public broker, and a client (cell phone, another arduino, etc.) subscribes to that topic to display information or receive instructions. Since the device that subscribes, or publishes to the broker initiates the conversation, your home router does not need network address translation or ports opened up. To secure the data transmission, usernames, passwords, client id's and SSL are used.

Our first step was to install Mosquitto on the server. We used the excellent tutorial at https://www.baldengineer.com/mqtt-tutorial.html to get the broker up and running, and tested. Since we used a windows 10 machine as the server, we had to enclose the message "Hello World" in double quotes instead of single quotes as stated in the tutorial.

There are two dependencies listed during the installation, so also download those, and copy the resulting dll's to the mosquitto directory.

Since I use MySQL and PHP to collect data from our sensors and log to the database, I created a php page that acts as a publisher to the broker. The sensor could just as easily publish to the broker directly, but I needed the database and visual graphing capability of PHP, CSS3, HTML5 and Javascript. I can also easily email alerts.

I may set up php as a subscriber, and have the sensors publish to the broker.

To use MQTT with PHP you need a MQTT Library for PHP.

Stay tuned for more articles using ESP8266's, relays and other sensors, with MQTT transport. I'll have a Mosquitto sandbox for readers to play with so you can publish and subscribe your sensors.

PHP Example Code:

https://pastebin.com/X2iewi60

Android viewing and control:

There is an very good Android dashboard for publishing and subscribing to the broker. You can see your sensor values, and send commands to your devices from anywhere in the world.

IoT MQTT Dashboard

Thursday, July 20, 2017

Infra Red Sensor Boards are Here!

The IR Sensor boards finally arrived! We are busy soldering components, writing new Arduino sketches to show off the capabilities of these boards, and preparing for full blown production. New videos are in the works, for when we get back from vacation. Each board supports up to 6 sensors (Reflex or Transmissive), and are ideal for block detection, crossing light / gate sensors, scale speedometers, and more.

The main difference between reflex couplers and transmissive sensors is in the relative position of the transmitter and detector with respect to each other. In the case of the transmissive sensor, the receiver is opposite the transmitter in the same optical axis, giving a direct light coupling between the two. In the case of the reflex sensor, the detector is positioned next to the transmitter, avoiding a direct light coupling.

Using a 6' piece of cat-5 cable, we connected the blue to the Anode of the IR LED, and blue/white to the Cathode. We connected green to the Collector of the photo transistor, and green/white to the Emitter.

I suggest a bit of hot glue once you solder and heat shrink the leads to the TCRT5000 IR pair.

On the board end, blue goes to LED+, green to PT+, and the blue/white and green/white to GND.

See our level crossing application, and our scale speedometer project.






Sunday, July 2, 2017

Posting ESP8266 weather data to server

Last week we connected a ICStation BME280 temperature / humidity / barometric pressure sensor to a a ICStation NodeMCU ESP8266. We displayed the collected data (along with Dew Point and Heat Index calculations) in the serial monitor.

This week we modified the sketch to post those variables to a linux server (could be your own local Raspberry Pi) running MySQL and PHP. We have it set to take a reading every 30 seconds, and post the data to a php page that inserts the data into the MySQL database. The index page displays a table of that data. The time and date stamp has been modified to display the data in the timezone of the location of the sensor. We are working on live gauges and graphs to display this data in real time.''

See the live data at http://theiot.zone/templog/

All code can be downloaded from https://drive.google.com/open?id=0ByRIq5k2wjcSXzVvamZ1dk9yQVU

Thanks to Nuno Santos and his tutorial at https://techtutorialsx.com/2016/07/21/esp8266-post-requests/ for some fine tuning of my code.


Friday, June 30, 2017

Median vs. Average, Arduino Calculations

If we want to average a set of numbers, we add them together, then divide by the number in the set.

150 + 200 + 0 = 350 / 3 = 116 Average

I'm using int and dropping the fractional parts. Use float if you need them.

But if we want the Median, which is the center, or middle number, we have to sort and compare each number to the others to get a list from high to low, and grab the center number. In this case, the Median is 150.

I've written a sketch that calculates both so you can compare your own numbers, and make it a much larger list:

int a[] = {150,200,0};
int n = 3;

a[] is your set of values

n is the number of values in the set

https://pastebin.com/Ge0pZGS2

More info on Mean, Median & Average - https://www.vocabulary.com/articles/chooseyourwords/mean-median-average/





Thursday, June 29, 2017

6 Channel Infra Red Transceiver Sensor Board

Calling all Model Railroaders (ok, it's not just for Model Railroading)! Remember our Scale Speedometer and Crossing Light project? We used IR transceivers in the track to detect a train passing overhead. Perfect for block detection and other projects. We are releasing a 6 channel IR sensor board (fully populated) for use with Arduino, Raspberry Pi, PIC and other microcontrollers. Comes with all components, including the 6 IR transceivers wired to 6' cords. All connections are screw terminals for ease of use. Each phototransistor has a potentiometer for adjusting sensitivity. Operates at 5v or 3.3v (select which version). Comes with sample code for Arduino.

Voltage Options

Sunday, June 25, 2017

Transistor Sizing Calculation

Two common ways of using a transistor is as an analog amplifier, or a digital switch. We are most interested in the digital switch mode of a transistor in our projects.

Many times, an Arduino, or other microcontroller, is not able to drive a load directly. We commonly will use a transistor to drive the load, and trigger it with a microcontroller's output pin.

For MOSFET examples, see our companion article.

Lets use an example. Say we have a 20v dc motor, that requires 500ma of current at load.

The Arduino UNO can output 5v, at 40ma or less. Let's use a 2N2222 transistor. From the spec sheet, we see it can handle 600ma continuously, so current requirements are met. We also see it can handle around 30vdc, so the voltage requirements are met. Looks like a good match.

Being a NPN transistor, the load attaches between the collector and the positive supply, the emitter connects to a common ground with the Arduino.

To prevent the transistor from pulling too much current from the Arduino, we need a resistor between the Arduino output pin, and the base of the transistor. The resistor must be sized to limit current to no more than 40ma, and to make sure the transistor "opens" fully under load. The more current drawn by the load, the more current is needed by the base.

Download spreadsheet with following calculations:

The 2N2222 has a DC gain of about 30, so the current of the load (500 ma) divided by the gain (30) means we need a base current of around 16ma.

If we assume a Arduino HIGH being around 4.5v, and the diode voltage of the transistor is 0.7v, we get a base voltage of 3.8v. The maximum size of the resistor to maintain a 500ma load will be 228 Ohms. We found this by taking the needed base current of 16ma and dividing by the base voltage of 3.8v (and multiplying by 1000). If you go higher, the transistor may not fully open, and the motor won't perform properly. We could go as low at 100 Ohms without exceeding the max current of the Arduino pin (3.8v / 100 Ohms = 38ma), but there's no need to draw the excess current, so keep the resistor value near the max of 228 Ohms to reduce Arduino power consumption, and leave capacity on other pins. The total current supply capability of the UNO is 200ma (per ground) across all the pins.

Saturday, June 24, 2017

ESP8266 BME280 Weather Station

One of our favorite new toys is the ESP8266 WiFi module. A very powerful microcontroller in it's own right, it's easily programmed with the Arduino IDE, and uses the same code we have come to know and love.

Update:
Now pushing data to web server!

So lets start:

We received a NodeMCU ESP8266 microcontroller and a BME280 Temperature / Humidity / Barometric Pressure module from IC Station.

Both the ESP8266 and the BME280 are 3.3v devices, so no level shifting required. The BME280 is an I2C device, so I connect SCL to D1 on the ESP8266, and SDA to D2. VCC goes to 3V3 and GND to GND. That's it for wiring.

I need to add the ESP8266 to the Arduino IDE, so head over to http://arduinotronics.blogspot.com/2017/03/arduino-esp8266-wifi-on-cheap.html for a quick tutorial.

You will need two libraries from Adafruit, both the BME280 and the Sensor libraries - https://github.com/adafruit/Adafruit_BME280_Library

I used their example sketch, but modified the metric outputs to American, and added calculations for Dew Point and Heat Index.

Once the board is installed, you are ready to upload the modified sketch: https://pastebin.com/rhkJGApY

The output of the serial monitor should look like this:


Our next step with this is to push the data to our new IOT web / database server, with live charts, gauges, and database storage. Stay tuned!

Check out all our videos on Youtube!

Friday, June 2, 2017

Logic Level MOSFETs, IRL or IRF?

If you need to switch a dc load, a MOSFET is a very useful component. Typically carrying much more current than a standard transistor, and better performance characteristics, like a high impedance gate that draws very little current. BJT's are current driven devices, MOSFETs are voltage driven devices.

Not all MOSFETs are the same, and too many Arduino sites show the IRF series MOSFET. The IRF series require 10v (VGS = 10.0 V) at the gate to fully open at anywhere near rated loads, so we use the IRL series. Any logic level N-Channel MOSFET (VGS = 5.0 V) will work, and look for the lowest RDS(on) (Ω) resistance you can practically find, to limit heat buildup. Connect your DC load between + and the Drain (D) of the MOSFET. Connect the MOSFET Source (S) to ground, or negative terminal of your voltage source. We add two resistors, a 10k Ohm from the MOSFET Gate (G) to ground to ensure turnoff when Gate signal is removed, and a 125 Ohm resistor between the Arduino output and the MOSFET Gate (G). This protects the Arduino pin from too much current draw. The value is determined by the voltage of the Arduino pin (5v) divided by the max current we want to allow (40ma). The IRL540 shown has a built in snubber diode that prevents motor flyback from damaging the MOSFET or Arduino. The Arduino sends a HIGH signal to turn on the MOSFET, a LOW to turn it off, and can also use PWM (analogWrite on an appropriate pin) to control motor speed, lamp brightness, etc.





Thursday, May 25, 2017

"Clear All" Checkbox Script

Ever need to have a "clear all" check box, and have any of the other check boxes clear the clear all? Well, we needed that, and came up with a solution for your coding pleasure. It's in PHP, but can be done in HTML as well. It uses a bit of javascript in either to make the magic happen.

Code: https://pastebin.com/kP701jQ4




Wednesday, May 3, 2017

Convert a UPC-A to a GTIN-14

More and more I'm having to use GTIN barcodes instead of the old UPC-A bar codes. I needed a way to automatically grab the UPC-A bar code number from our database, strip the check digit, and generate a new GTIN-14 bar code on the fly, with a newly recalculated check digit. This is done in PHP, so take a whack at it and have fun! I'm still investigating how to produce bearer bars.

The trick to generating a check digit is list the 12 digit UPC-A with two zeros as a prefix, and starting with the first position on the left, mark the numbers as the Odd and Even positions, leaving off the last digit (check digit).

00  6631    2102    3756
OE OEOE OEOE OEOX

Add all the Odd positions together :19
Add all the Even positions together: 17

Multiply the Odd total by 3: 19*3=57

add the Odd and Even totals together: 57+17=74

If a multiple of 10, check digit is 0. In our example case it's not, so if not a multiple of 10, Subtract from the next higher multiple of 10: 80-74 = 6

6 is the check digit. Now add a 01 prefix in front and you have a GTIN-14 compatible bar code.

01 0066312102375 6


Code:
https://pastebin.com/32QRkPZ5

Tuesday, April 25, 2017

Display a TextBox only when a Radio Button is Checked

I was working on one of my websites this week, and needed the ability to allow the user to input some text only when a certain radio button is checked, and make the TextBox go away when another radio button is checked. All the TextBox's are hidden on page load, then activated when the "Other" radio button is checked. I also use placeholder="" to give the user some idea of what goes into the box.  After a few tries, I got it working and figured, if I needed this, others may as well, and to save you some time and angst, here is my code. Works well in HTML or PHP (just add echo' ... '; pieces).

Enjoy!

Code:
https://pastebin.com/LA9YxXQh

Friday, March 31, 2017

Calculating Amp Hours and Watt Hours

In previous posts we have described how to make a volt/amp/watt meter to measure power consumption, or production (solar, wind, etc). I never fully explained the watt hour and amp hour calculation, so here is a sample sketch that assumes you are measuring voltage and current with the appropriate sensors.

http://arduinotronics.blogspot.com/2015/05/reading-current-shunt-with-arduino.html

http://arduinotronics.blogspot.com/2012/04/voltage-monitor.html

I'm flushing the daily data every 24 hours, but keeping a running total. You could save this data to a sd card or publish it to a web server.

http://arduinotronics.blogspot.com/2014/04/add-logging-to-your-project-for-250.html

http://arduinotronics.blogspot.com/2015/12/sending-sensor-data-to-web-server.html

This is much easier to read on a LCD instead of the serial monitor.

Code:


float volts = 120; // get value from voltage sensor
float amps = 100; // get value from current sensor
float watts = volts * amps;
float kwh;
unsigned long totalET;
float dailykwh;
float totalkwh;



void setup() {
 
Serial.begin(9600);

}

void loop() {
 
  uint32_t ts1 = millis();
  delay(1000); //reports at 1 second intervals
  uint32_t ts2 = millis();

  // print the time interval in seconds
  uint32_t ts3 = (ts2-ts1)/1000;
  totalET = totalET + ts3;
  Serial.print("Seconds: ");
  Serial.println(totalET);

  kwh = watts * ts3 / 3600000;
  dailykwh = dailykwh + kwh;

  Serial.print("Volts: ");
  Serial.println(volts, 4);
  Serial.print("Amps: ");
  Serial.println(amps, 4);
  Serial.print("Watts: ");
  Serial.println(watts, 4);

  //Serial.print("Current Ah: ");
  // numbers so small it's not relevant.
  //Serial.println(kwh/volts, 4);
  //Serial.print("Current KWh: ");
  // numbers so small it's not relevant.
  //Serial.println(kwh, 4);

  Serial.print("Daily Ah: ");
  Serial.println(dailykwh/volts, 4);
  Serial.print("Daily KWh: ");
  Serial.println(dailykwh, 4);
  totalkwh = totalkwh + dailykwh;
  Serial.print("Total KWh: "); //from reboot
  Serial.println(totalkwh, 4);
 
  if (totalET >= 86400){ //restart every 24 hours
  ts1 = 0;
  ts2 = 0;
  totalET = 0;
  dailykwh = 0;
}
}

Wednesday, March 29, 2017

Outlook lost it's search capability?

This is a bit off topic for this blog, but since Outlook is a common email client, I thought I'd pass along a little tip.

All of a sudden, Outlook started responding to searches with "No Results Found". Called Microsoft, and wonder of wonders, they sent out a bum patch. While they are attempting to fix, there is a work around. Revert back to a working build.

In Outlook, click File, Office Account, and set Update Options to Disabled.

Open a cmd prompt as administrator (right click on the command prompt icon and choose More, run as administrator).

In the cmd prompt, type (or copy / paste):

cd %programfiles%\Common Files\Microsoft Shared\ClickToRun

press Enter, then do the same with this command:

officec2rclient.exe /update user updatetoversion=16.0.7571.2109

This will run a lengthy update, but when finished, Outlook will have it's search back.

Set a calendar reminder to turn the updates back on in a month or so.


Wednesday, March 22, 2017

Arduino ESP8266 WiFi, on the Cheap!

If you are looking for Wifi for for your Arduino Project, look no further! For less than $9 you can add wifi capability to your Arduino Project, without loading down your Arduino with a bunch of network access code. We used a HiLetgo New Version NodeMCU LUA WiFi Internet ESP8266 Development Board for the access link. Now this board has a bunch of 3.3v I/O capability all on it's own, and is easily programmed using the Arduino IDE, but our goal is to use a Arduino NANO for I/O and just use the ESP8266 for the network link.

Installation was not straightforward, but not difficult either. The board uses a standard USB A-Male to Micro B cable used with most cell phones. Plug the cable into the ESP8266 and your computer. If you are on Windows, check your device manager to see what port has been connected. If you have a yellow exclamation mark on the device (Silicon Labs CP210x), right click it and choose Update Driver Software.

Now open a recent version of the Arduino IDE (1.6.4 or greater). Under File - Preferences, add http://arduino.esp8266.com/stable/package_esp8266com_index.json to the Additional Boards Manager URLs field, and click OK.

Now go to Tools - Board - Boards Manager and scroll down to ESP8266. Select ESP8266 and click Install.


Now to use the board, Go to Tools - Board, and select the Adafruit HUZZAH ESP8266. Others may work better, but that's the one I started with.

Remember, this board uses 3.3v logic, so no 5v connections to the I/O pins.

The sample sketch I tried worked first time, and connected to the web server right away. See https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-ide for code.

Use the D0-D10 and A0 pins printed on the board the same as the pins on an arduino (given the 3.3v caution). The pinouts are below:


For a cool "Breathing" effect of the onboard LED at pin "0" (D0, or GPIO16), see https://arduining.com/2015/08/20/nodemcu-breathing-led-with-arduino-ide/

Wednesday, March 8, 2017

Encryption fun, win an Arduino!

Here's a challenge for you all. I'm posting a picture, and a coded phrase. Figure it out, email me, and the first 5 winners get an Arduino Nano clone, and their names (or hacker names) listed as really smart (and geeky) folks!

59221 91430 8117 94007 21268 100714 58135 73658 29992 52388 103243 47570 29961 38689 74327 56189 45120 64972 81138 106187 18809 11348 10965 32969 70849 96470 6350 56264 69516

After the contest is over, I'll post the code, and some really interesting tips on passing virtually unbreakable messages.

Clue: it's a variation on a book cipher!

Next Clue: the numbers above are the positions of the characters in the "book".

Solution:

The image is base64 encoded. That creates the book. Then go to position 59221 and write down the letter found, then position 91430 , and so on.

In the files below, I've built a php based set of utilities for choosing an image, saving it in an uploads folder, and creating the encoded ascii file. You then can input the string to be encoded, and it returns character positions from the "book".  I used a date/time seeded random function to choose one of the available results for each character submitted to reduce the possibility of repeat distribution hacking.

The decode file takes those position codes, and spits out the original phrase. No one has posted the phrase, but the contest is over. Hope you had fun!

https://drive.google.com/open?id=0ByRIq5k2wjcSbGVBaWc4bmFGN00

Tuesday, February 14, 2017

KK4HFJ HF Station is up and running!

I finally made the move from 2m EmComm's to HF work. I'm still working 2m off the local repeaters, but it's nice to be able to reach around the world. I installed a Kenwood TS-430 HF rig, a AT-250 Antenna Tuner, a MFJ G5RV dipole, and a dell server power supply to keep it all fed and quiet. You can find me most evenings on 40m, usually around 7.18 Mhz.

KK4HFJ Monitoring .....

Friday, January 27, 2017

STEMTera - Arduino in a LEGO Breadboard

Sparkfun is coming out with a new breadboard that includes a Arduino in a LEGO compatible base. All the ATmega328P and ATmega16U2’s I/O pins are broken out and available. The breadboard has shield compatible pinouts (yes, the weird offset is there). A bit more than you would pay for a Arduino UNO, but the convenience of having a breadboard and complete access to all the pins makes up for it. This is a perfect teaching tool!

https://www.sparkfun.com/products/14082


Tuesday, January 3, 2017

Model Railroad Crossing Lights

For the Charleston Area Model Railroad Club, We have combined our train detector circuit from the scale speedometer project with a LED Crossing Light to make it simple to indicate a train is coming to a crossing. The next step is to add a servo operated crossing bar, and bell sounds, but I'm getting ahead of myself.

Get the IR sensor board at http://arduinotronics.blogspot.com/2017/06/6-channel-infra-red-transceiver-sensor.html


The Circuit:
The detection circuit is the same as the scale speedometer. A TCRT5000 IR LED / Phototransistor pair, with two resistors, connected to an Arduino input (D8). You can lower the value of the Phototransistor pullup resistor to 10k-50k ohm (instead of 80k-100k ohm) to reduce it's sensitivity to ambient light. Increase the value of the IR LED resistor (68 Ohm) to reduce range. Never drop IR resistor below 68 Ohms.

The output is a off the shelf LED crossbuck with 2 red LED's and a common anode. I put a 300 ohm resistor on the common and connected to 5v, and connected the two cathodes directly to arduino outputs D11 and D12. Add a second LED Crossbuck (with resistor) to the same outputs for the other side of the crossing. See the video below the code.
The code checks to see if the phototransistor is lit (a 0 or LOW), and activates the lights (LOW is lit, HIGH is off)) as long as it is.


//int sensor1 = 1;


void setup() {
  Serial.begin(9600);
  pinMode(8, INPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(11, HIGH);
  digitalWrite(12, HIGH);

  int sensor1 = digitalRead(8);
  Serial.println(sensor1);
  if (sensor1 == LOW){
    digitalWrite(12, HIGH);
    digitalWrite(11, LOW);
    delay(1000);            
    digitalWrite(12, LOW);
    digitalWrite(11, HIGH);
    delay(1000);
  }
           
}


Finished board for two track sensors and 2 crossing lights.



Monday, January 2, 2017

Model Railroad Turnout Control - Arduino MOSFET

One of the projects we are working on is Turnout Control. Most home layouts are using Atlas or Bachmann track with solenoid type turnouts like the one shown here. More professional layouts use slow moving motors like the Tortoise. Our goal is to make these turnouts controllable with an arduino, so that future projects using train detectors and DCC can allow more automation. So here is the beginning of our project. This one uses the above Bachmann turnout (arduino servo control article coming soon), a arduino nano, two IRL520 MOSFETS, two resistors, and two diodes. The schematic is as follows:


The diodes protect the MOSFET from inductive spikes when the solenoid coils fire. The two MOSFETS engage the solenoid coils to move the turnout. the two resistors keep the MOSFET from randomly conducting when there's no input signal, by pulling the gate to ground (off). This uses two digital outputs on the arduino called straight and turn. The next article will show the board layout and wiring of the arduino, turnout and power supply. For more projects based on MOSFETS, see http://arduinotronics.blogspot.com/search?q=mosfet

Related Posts Plugin for WordPress, Blogger...