My Arduino Projects

First step in building a web connected garden.  Plan to use this moisture reading setup to send an email when the plant gets too dry.

Facts:

  1. 10K ohm resistor
  2. Nails 6 inches apart
  3. PWM analog read from the pin was hovering around 650 (this was 3 days after watering plant)
  4. After pouring some water over the nails the reading was around 730

Code:


This project uses a Teensy microcontroller programmed with Arduino. It is intended to be a bathroom door indicator. Those who are far from the bathroom can install a client program on their computer that runs in the system tray. When the bathroom is closed and unavailable the stoplight shows red. When the door is open the stoplight shows green. Essentially indicating when the bathroom is occupied.

The magnetic switch closes the circuit and the Teensy relays the message over the USB. A Processing language program reads the received byte and tweets a message that will be interpreted by the Java client program running (the system tray stoplight).

Programming relies on the terrific Twitter4J library for Java.


First Hookup of NES Controller.  Outputs to Serial.

Excellent Schematic here: http://seb.riot.org/nescontr/

Copied below:

image

Explanation how a Shift Register works: http://en.wikipedia.org/wiki/Shift_register

Example Arduino Shift Register project: http://www.oomlout.com/a/products/ardx/circ-05


TKTS Ticker Tape Arduino Code

/*
 * DNS and DHCP-based Web client
 * Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 */

#include <SPI.h>
#include <Ethernet.h>
#include <SoftwareSerial.h>
#include <Thermal.h>
#include <TextFinder.h>


// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0x90, 0xA2, 0xDA, 0x00, 0x9D, 0x51 };
char serverName[] = "serverRedacted";

const int ledGreen = 7;
const int ledRed = 6;
const int ledYellow = 8;
const int button = 5;
#define ON LOW
#define OFF HIGH

int printer_RX_Pin = 14;
int printer_TX_Pin = 15;

Thermal printer(printer_RX_Pin, printer_TX_Pin);
EthernetClient client;

void setup() {
  pinMode(ledGreen, OUTPUT);
  pinMode(ledRed, OUTPUT);
  pinMode(ledYellow, OUTPUT);
  pinMode(button, INPUT);
  digitalWrite(button, HIGH); //turn on internal pull-up resister  
  
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    digitalWrite(ledRed, HIGH);
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  digitalWrite(ledYellow, HIGH);
  
  printer.setSize('S');
  printer.justify('L');
}

void connectToServer();

#define MAX_TITLE 26
#define RIGHT_ALIGN 29
int length;
char s[MAX_TITLE], t[MAX_TITLE];
int percentage;
TextFinder finder(client);

void loop()
{
  if(digitalRead(button) == ON && !client.connected())
  {
    delay(500);
    Serial.println("connecting...");
    connectToServer();
  }
  if (client.available()) {
    digitalWrite(ledRed, LOW);
    digitalWrite(ledYellow, LOW);
    digitalWrite(ledGreen, HIGH);
    
    //finder doesn't use a buffer so must create a test first
    //that doesn't pass here so we don't search file for PostDateTime
    //because it only exists once
    if(!strlen(t) && finder.find("PostDateTime\":")){
        length = finder.getString("\"", "\"", t, MAX_TITLE);
        Serial.println("****TKTS BOOTH TICKER TAPE****");
        Serial.println(t);
        
        printer.justify('C');
        printer.println("****TKTS BOOTH TICKER TAPE****");
        printer.println(t);
        printer.justify('L');
    }

    if(finder.find("Name\":")){
        length = finder.getString("\"", "\"", s, MAX_TITLE);
        Serial.print(s);
        Serial.print(": ");
        printer.print(s);
        
    }
    if(finder.find("Percentage\":")) {
        percentage = finder.getValue();
        for(int i = 0; i < RIGHT_ALIGN-length; i++) {
          Serial.print(" ");
          printer.print(" ");
        }
        Serial.print(percentage);
        Serial.print("%");
        Serial.print("\n");
        
        printer.print(percentage);
        printer.print("%");
        printer.print("\n");
    }
  }
  if(!client.connected())
  {
    Serial.println("disconnecting.");
    printer.feed();
    printer.feed();
    printer.feed();
    t[0] = 0; //revert so that the title prints
    
    client.stop();
    digitalWrite(ledGreen, LOW);
    digitalWrite(ledYellow, HIGH);
    while(digitalRead(button) == OFF);
  }
}

    
void connectToServer()
{
    if (client.connect(serverName, 91)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET requestRedacted");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
    digitalWrite(ledRed, HIGH);
    digitalWrite(ledYellow, LOW);
  }
}