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.

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 I headed on over to Instructables 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.

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

Saturday, December 31, 2016

Arduino Cousins Rejoined in 1.8.0

The two forks of the Arduino IDE have been rejoined into one. No longer are there separate IDE's from Arduino.cc and Arduino.org. Boards from both companies and new additions from Adafruit are supported. This is great news for the Arduino Community. Requires Java 8 to run, but well worth the upgrade!


Arduino IDE 1.8.0 works out of the box with AVR boards, like the Uno, Mega, Yun, and Micro, among the most popular. Additionally, it supports the Leonardo Ethernet, Yun Mini, Industrial 101, and Uno WiFi.

The updated SAMD core will provide support for the M0 and M0 PRO, completing the product line that includes the Zero, MKR1000, and the newly-launched Primo and MKRZero.

Wednesday, December 28, 2016

The Pixel OS Controversy

There's been a lot of "news" about the Raspberry Pi Foundations new Pixel OS. Lets dig in and take a look at what the hubbub is all about.

First of all, contrary to much of the misinformation by the BBC, Guardian, and others, it's not an OS.

It's an alternative DE (Desktop Environment), much like gnome, LXDE, and others, that sits on top of a linux OS. That's it, nothing more.

As a DE, it's lightweight (needed for limited resource machines like the Raspberry Pi), and very pretty. It's fully available for the Raspberry Pi, or you You can download an image bundled with debian and try it in preview mode on a intel based pc. Preview mode? Yes, you cannot install it on your computer, as it's a "developmental beta", not an installable DE.

The good news? Eventually it will be a usable option not only on the Raspberry Pi, but other platforms like Intel based pc's. Eventually.