Testing Your Arduino


On this page


You connect the Arduino to your computer using a USB cable. This cable is used to communicate with the board as well as power it.

The first time you connect the Arduino, Windows will install drivers. After that you can start the Arduino IDE and check the "Tools" menu to make sure the correct Board is selected as well as a Port (usually COM3 or COM4).

The Arduino site has a more involved process for installing the drivers. So if automatic driver installation failed on your computer you could check there how to do it.


Your Arduino might come pre-loaded with the Blink program, in which case the orange LED on the board is now blinking. Regardless, we can still use this program to test the Arduino.

First, open the example sketch by opening the File menu and selecting Examples > 01.Basics > Blink. The code is pretty simple and has comments to explain everything:

void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second

The delay(1000) statement works with milliseconds (1000ms = 1s). If the LED is already blinking, you can change both 1000 values to 500 to have it blink twice as fast, or 2000 for twice as slow. Then click the Upload button in the toolbar of the Arduino IDE. The LEDs on the Arduino will blink very fast while it's uploading and then the program will execute. If all went well, a single LED should now be blinking at the pace you specified.

Temperature - Connections

Now we're ready to use our DHT sensor to measure temperature and humidity. It doesn't matter if you have a DHT11 or DHT22. The 22 is a little more sensitive, that's all. Besides the DHT you'll also need some wires and a 10k resistor.

Connect the wires like this:
DHT22 connections
In electronics, it's custom to use a red wire to connect to power and black to connect to ground.

On the DHT22 (and DHT11), the leftmost pin is for power, and the rightmost is connected to ground. The second pin from the left is where we read the data, so that's connected to a digital pin on the Arduino (in our case, D2). We also need to add a pull up resistor to make measurements more reliable.

Temperature - Sketch

First download the DHT library by Lady Ada. If your Arduino folder is in the default location, go to My Documents > Arduino > libraries, and make a folder named DHT. Place the DHT.cpp and DHT.h files in there. Then download the sketch and upload it to your Arduino.

Alternatively, you can install the codebender plugin and upload the Arduino sketch right from your browser!

(if you can't see a codebender frame here, one of your extensions might be unintentionally blocking it, like AdBlock or Privacy Badger)


Now we go back to the Pi and set up the message broker.