Posted on Leave a comment

Simple Arduino Temperature, Moisture and Light Monitor

Simple Arduino Temperature, Moisture and Light Monitor

Recently I planted some succulent seeds indoors, and had to put them in a miniature greenhouse so that they could sprout. I wanted a way to keep an eye on the temperature, moisture and ambient light in the greenhouse, so I whipped this up. It outputs realtime measurements to an LCD. If you’ve seen my ProGrow project, this is a simplified version without any data storage or relays.

Parts

I used an old scrap 3D print for the frame; it’s just a block of plastic that I screwed everything to. The electronic parts used are:

A quick overview of each component and why I’m using it:

  • Arduino Nano
    • Extremely low cost (<$3)
    • Ready to go ATMega328p board with voltage regulators and USB
    • Lots of expansion opportunities
  • Arduino Expansion Board
    • Makes life easier for prototyping/wiring with the Nano
  • FC-113 + 16×2 LCD
    • Cheap and easy to use LCD combo
    • Only requires two analog pins for communication, easy to set up
  • Photoresistor module
    • Works just like a photoresistor with an analog signal, but it also has a digital output
    • Has an indicator LED and potentiometer for the digital output
  • DHT11 Temperature/Humidity Module
    • Very cheap, easy to use and decently accurate
    • DHT22 is a better version with higher accuracy, but is more expensive
    • BME280 is far superior to DHT11/DHT22, but is more expensive

Connecting everything to the Arduino

Schematic for Temp/Humidity/Light Sensor
Schematic for Temp/Humidity/Light Sensor

The DHT11 module has 4 pins, but only three are used:

  •  Vcc to +5V
  • Signal to Digital Pin 5
  • Gnd to Gnd

The photoresistor module I am using also has 4 pins, and only three are used. The analog output of the module is used over the digital output. You can get the same functionality with just a resistor and a photoresistor.

  • Vcc to +5V
  • Aout to Analog pin 1
  • Gnd to Gnd

The LCD module is connected to the FC 113. The FC 113 is connected in the following manner:

  • Vcc to +5V
  • SCL to Analog pin 5
  • SDA to Analog pin 4
  • Gnd to Gnd

The arduino nano can be powered through USB with 5V, or through the Vin pin with 7V-12V.

Programming

Programming the Arduino for this is pretty straightforward. All the Arduino has to do is take a measurement from the DHT11 and photoresistor, and then output them to the display. 

There are libraries available for the DHT sensor, and the FC 113 module, so the whole process is straightforward.

Before starting

You need two libraries to make things easier, one for the DHT11 and one for the FC 113.

You can download the DHT library I used at:

https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib

You can download the FC 113 library I used at:

https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library

How to install libraries:

https://www.arduino.cc/en/Guide/Libraries

Before Setup

//Temp/Humidity/Light Monitor V0.1
#include //Import LcrystalI2C for FC 113 + LCD module
#include //Import DHT for DHT11 temperature/humidity sensor
int tempSensor = 5; //Digital pin 5 for temperature sensor
int lightSensor = A1; //Analog pin 1 for light sensor
dht DHT; //Sets up dht11 as DHT

First I include the required libraries.
Then, I establish pin 5 for the temperature sensor and analog pin 1 for the light sensor.
Finally, I set up an object called DHT to handle data from the DHT11 sensor.

Setup

void setup(){
Serial.begin(9600); //Establishes serial at 9600
lcd.init(); //Initialize the lcd
lcd.backlight(); //Initialize LCD backlight
lcd.clear(); //Clear LCD
Serial.print(analogRead(lightSensor)); //Print currently photoresistor value to serial; for troubleshooting purposes
}

The setup just consists of initializing the LCD module, and printing a simple message to the serial monitor as an optional self-check.

Loop

void loop(){
DHT.read11(tempSensor); //Reads information from tempSensor(pin 5), stores in DHT
lcd.setCursor(0,0); //Sets cursor of LCD to very first position
lcd.print("H: "); //Prints H: , for humidity
lcd.print(DHT.humidity); //Outputs humidity
lcd.setCursor(0,1); //Sets cursor of LCD to first position, second line
lcd.print("T: "); //Prints T: , for temperature
lcd.print(DHT.temperature); //Outputs temperature
lcd.print(" C"); //Prints C for celcius
delay(4000); //Delays for approximately 4 seconds
lcd.clear(); //Clears the LCD
lcd.setCursor(0,0); //Resets cursor to first position
lcd.print("Lux: "); //Prints Lux, for light level
lcd.print(analogRead(lightSensor)); //Outputs lux value
delay(4000); //Delays for 4 seconds before looping
}

The loop starts by reading the DHT11 sensor, and storing the values in the DHT object. Then, it outputs the information to the LCD. It delays for a few seconds, and then it reads the light sensor. It continues in a loop like this, reading and then outputting. You can adjust the delay to change how often the display updates the values, and you could take it one step further by implementing a button so that the display only updates when you push a button.

Posted on Leave a comment

3D Printed Arduino + Bluetooth Tank

3D Printed RC Tank

I’ve been working on a new remote controlled tank in my spare time. My goal with this project is to make a cheap, printable RC tank kit. This post goes back and forth between talking about the tank, and a basic tutorial on how the components and code work together.

Currently it’s a working prototype. The tank uses an Arduino Nano clone (ATmega328) as the primary board. An L298n H-Bridge is used to control the left and right motors independently, allowing it to quickly turn or revese. It uses the HC-06 Bluetooth module to receive commands. The power comes from two 18650 batteries that are connected in series.

3D Printed RC Tank

 

Hardware:

I purchased the majority of the hardware from Aliexpress, because it’s so cheap. The links below are to the stores that I used, but you can find the same parts on many websites other than Aliexpress.

  • Arduino Nano V3 Clone ( AtMega328p ) – Link
  • L298n H-Bridge Motor Controller – Link
  • HC-06 Bluetooth Module – Link
  • 2x DC Motor + 64:1 Gearbox – Link
  • 2x 18650 Battery – I took mine from an old laptop, wired them in series for 7V+
  • 1x 500mA Polyfuse – Optional, put between power source and VIN

 

I salvaged some steel weights from an old set of window blinds, and super-glued them to the base to add some weight.

Tank Front View
Tank Front View

 

Frame:

The frame of the tank was printed as a solid piece. There are four mounting spots for wheels. The two at the front are designed so that small bearings will slot into them, so that the front wheels spin freely. The other two of the mounts are designed to hold the gearbox motors. I made a T-shape in the center of the frame so that I can mount a breadboard on top of the frame. The frame design leaves much to be desired, it’s much too thin and flexible.

This slideshow requires JavaScript.

The front and rear wheels have teeth that are spaced out, so that they catch on the inside of the cable-chain tracks. The teeth are tapered slightly to keep the tracks aligned, and there is a guard on the front wheels to ensure that they stay on. The battery holder has holes in the sides and bottom so that wires can pass through. Screws hold the wheels in place.

RC Tank Sideview
RC Tank Sideview

 

Schematic:

The Arduino and L298N are powered using two 18650 batteries. These are fairly common rechargeable batteries, with an output around 3.7V. I wired my batteries in series. My schematic says 7.2V, that’s a typo, it’s really 7.4V+. I use the VIN pin on the Arduino Nano to power the chip.

The 5V output on the Arduino powers the HC-06 module. Make sure that you’re using an HC-06 module with a breakout board like mine, so that it is 5V tolerant. This is because the raw HC-06 chip is NOT 5V tolerant.

Pins 2 and 3 are connected to the HC-06, and pins 4 through 7 are connected to the L298N. On the L298N, pins ENA and ENB are used for PWM control of the outputs, so that you can achieve finer speed control. I don’t utilize these, so they are set high.

Schematic

 

Code:

There are only two main components to control other than the Arduino itself, they are the HC-06 and the L298n. The HC-06 is going to receive data from an external source, and then pass it to the Arduino. Then the Arduino will make a decision, and send signals to the L298N to turn on the motors.

There is a link at the bottom to download the full code, or read through and copy/paste the example blocks.

 

Startup:

The program imports the SoftwareSerial library, and establishes pins for motor control. A char named btData is used to handle incoming Bluetooth data. Then pins 2 and 3 are declared as RX and TX using SoftwareSerial.

//SoftwareSerial library is included so that we can utilize pins 2 and 3 for the HC-06
#include <SoftwareSerial.h> //Pins 4, 5, 6, 7 used for motors.
const int motorRF = 4; //RF = Right motor, Forward direction 
const int motorRR = 5; //RR = Right motor, Reverse direction 
const int motorLF = 6; //LF = Left motor, Forward direction 
const int motorLR = 7; //LR = Left motor, Reverse direction 
char btData; //char used for bluetooth data - receives commands like "1", "2", "a", etc. 

SoftwareSerial HC06(2,3); //RX, TX - Pins 2 and 3 used for HC-06 Module

 

Setup:

Serial communication is set up, and a string saying “Hello” is sent as a self-check. Then digital pins 4, 5, 6 and 7 are declared as outputs, in order to send signals to the L298n.

void setup() {
  HC06.begin(9600); //Begin serial at 9600 baud as "HC06"
  HC06.println("Hello."); //Sends "Hello." through serial, to acknowledge startup

  pinMode(motorRF, OUTPUT); //Sets pins 4 through 7 to OUTPUTs, to control the L298N
  pinMode(motorRR, OUTPUT);
  pinMode(motorLF, OUTPUT);
  pinMode(motorLR, OUTPUT);
}

 

Loop:

The loop works by cycling until data is available at the HC-06 module. When data is received, it enters the loop and then makes decisions. In this case, I use the numbers 1 through 4 to control the state of the L298N. When a ‘1’ is received, the Arduino sets pins 4 and 6 to HIGH, so that the L298N enables the outputs in a manner that turns both motors forwards. I use a delay function, so that it keeps the motor on for a second.

void loop() {
  //Loops until data is sent to HC06
  
  if (HC06.available()){ //When data is available in the HC06, do this
    
    HC06.println("Reading."); //Prints "Reading." through serial, to acknowledge incoming data
    btData = HC06.read(); //Reads "HC06" and stores the value into the char "btData"

    if (btData=='1'){ //If the HC-06 receives a 1, do this
      HC06.println("Forward."); //Sends "Forward." through serial, to acknowledge that a 1 was received
      digitalWrite(motorRF, HIGH); //Activates the motors so that the tank moves forwards
      digitalWrite(motorLF, HIGH);
      delay(1000); //Delays for approximately one second
      
    }
    if (btData=='2'){ //If the HC-06 receives a 2, do this
      HC06.println("Reverse."); //Sends "Reverse." through serial, to acknowledge that a 1 was received
      digitalWrite(motorRR, HIGH); //Activates the motors so that the tank moves backwards
      digitalWrite(motorLR, HIGH);
      delay(1000); //Delays for approximately one second

    }
    if (btData=='3'){ //If the HC-06 receives a 3, do this
      HC06.println("Left."); //Sends "Left." through serial, to acknowledge that a 1 was received
      digitalWrite(motorRF, HIGH); //Activates the motors so that the tank rotates left
      digitalWrite(motorLR, HIGH);
      delay(1000); //Delays for approximately one second
    }
    if (btData=='4'){ //If the HC-06 receives a 4, do this
      HC06.println("Right."); //Sends "Right." through serial, to acknowledge that a 1 was received
      digitalWrite(motorLF, HIGH); //Activates the motors so that the tank rotates right
      digitalWrite(motorRR, HIGH);
      delay(1000); //Delays for approximately one second

    }
    digitalWrite(motorLF, LOW); //Turns all of the motors off, by setting everything to LOW
    digitalWrite(motorLR, LOW);
    digitalWrite(motorRF, LOW);
    digitalWrite(motorRR, LOW);
  }
}

Download the full code here.

 

Connecting to the HC-06

I use the mobile app Bluetooth Electronics to connect to and send commands to my HC-06 module. I like using my phone since I can follow the car around. You can also use PuTTy, or another program to send serial commands to the HC-06 from a laptop or desktop.

The HC-06 becomes available for pairing when it is powered on. Pair your device with it, using the default password of “1234“. Once your device is paired with the HC-06, you’ll be able to connect to it using your program of choice.

To connect to it using Bluetooth Electronics, make sure that you’ve paired your device with the HC-06 and then open Bluetooth Electronics. Click “connect” at the top, and select your HC-06 from the list. Assuming you wired it correctly and it’s paired, you will now be able to send commands to it through the app. The app makes it incredibly simple to create a customized GUI for sending commands to the tank.

 

Future Design Ideas

I plan on making a lot of changes to this tank. I’m going to redesign the majority of the frame and the connection points on the wheels so that they are stronger. I want to increase the number of batteries to 3, so that it’s capable of higher speeds. The battery holder design is a little bit too short, requiring tape to stay closed, so I’ll fix that in the next revision.

 

I am working on a standalone program so that the project can be controlled in an easier manner. Instead of having it drive for predetermined lengths of time according to command-line strings, I plan on having a GUI with realtime feedback. There are a lot of options for making a program like this. I have been experimenting with python to some success, but I might resort to using one of the many application builders that are available. For right now, the Bluetooth Electronics app meets all of my requirements so I’ll continue down that path until I need more complicated functionality.

 

A great upgrade for the system would be to use an ESP8266. It would provide greater control options, and it would lower the cost and footprint. The extreme simplicity of the Arduino and HC-06 combination make it very easy to use and adapt, so I am going to continue using it for this project. Plus, I have a bunch of Nanos and HC modules sitting in a drawer collecting dust; it’s about time I turned them into something. My next RC vehicle project will hopefully utilize wifi.

 

More on this project is coming.

Thanks for reading!

 

Posted on Leave a comment

Arduino – Spare Parts Robot Car Prototype

Arduino Robot Car

Last night I was pretty bored, so I decided to build a simple robot car. I’ve only put a few hours of work into it so far, but it drives and steers! Sort of.

This slideshow requires JavaScript.

 

 

Parts used:

1x Arduino Nano

1x LiPo Battery

2x TIP120 Transistor

1x Servo Motor

1x DC Motor Gearbox

2x 2k Resistors

1x Breadboard

4x Wheels

 

The TIP120 transistor was only used because I had a bag of them within arms reach. The TIP120 works fine for this application, but it is inefficient and has lots of drawbacks. A FQP30n06l is much better for this application.

 

Schematic:

Schematic View of Car Circuit
Schematic View of Car Circuit

Code:

Literally all this code does is make the car accelerate gradually and wiggle the steering.

#include <Servo.h>
Servo steering;
int driveMotor = 3; //Digital 3 used for TIP120 on drive motor
int steerMotor = 6; //Digital 6 used for TIP120 on steering servo
void setup() {
    steering.attach(9); //Attach the Servo motor to digital PWM pin 9
}

void loop() {
    analogWrite(steerMotor, 255); //Turns the TIP120 on for the steering servo
    steering.write(90); //Sets the steering to 90 deg
    delay(250); //Waits a bit, for the servo to get to place
    analogWrite(steerMotor, 0); //Turns off the TIP120 to the servo
    analogWrite(driveMotor, 255); //Turns on the drive motor

    for (int i=80; i<=255; i++){  
        delay(25);
        analogWrite(driveMotor, i); //Gradually accelerates by switching TIP120, starting at 80/255
    }
    
    delay(250);
    analogWrite(driveMotor, 0); //Turns off the drive motor
    analogWrite(steerMotor, 255); //Turns the TIP120 on for the steering servo
    steering.write(45); //Sets the steering to 45 deg
    delay(250); //Waits a bit, for the servo to get to place
    steering.write(135); //Sets the steering to 135 deg
    delay(500); //Waits a bit, for the servo to get to place
    analogWrite(steerMotor, 0); //Turns off the TIP120 for the steering servo
}

Design:

The body of the vehicle is a 94:1 gearbox and the DC motor that drive the rear wheels. I attached a breadboard to the top of the gearbox to hold the circuitry. The servo motor responsible for steering is mounted on the front of the gearbox, and a 3D printed bracket holds the front wheels to the servo horn. It’s a pretty poor steering system, to be honest. I used zip ties and double-sided tape to keep everything stuck together.

Frame Design
Frame Design

The front wheels are some old attempts at Emmets Bearings that I found in my failed print bin. They spin well, but are awfully ugly. I designed the rear wheels myself using 3DS Max.

Rear Wheel Design
Rear Wheel Design

The obvious next step is to add a dedicated supply for the Arduino, so that the car is completely independent. It also needs basic wireless control; I’ll likely use IR. It also needs an actual frame and some proper wiring… and a lot more. It’s a work in progress.