volt meter

I made a volt meter!

using the arduino board to measure voltage

using the arduino board to measure voltage

All I have is a jumper wire poked into the analog pin 0 receptacle.  At samples 3 and 4 I have touched the end of the wire, bringing the voltage to ground.  Pretty exciting!  The code is below.

I’m working towards building my lightning detector.  I have a simple coherer, but haven’t gotten to see if it actually works yet.

// a simple volt meter
// version 0.1

float Vref = 5; // volts

int Rate = 1; // hz
int del = 1/Rate * 1000; // sample rate, ms

int vpin = 0; // which pin should be used to measure the voltage
              // make sure you connect the arduino system ground to the same
              // as the measurement system

int val_adc = 0; // adc counts
float val_volts = 0; // volts

int i = 0;

void setup() {
  Serial.begin(9600);
  Serial.print("delay between samples is ");
  Serial.print(del);
  Serial.println(" ms");
}

void loop() {
  delay(del);
  val_adc = analogRead(vpin);
  val_volts = Vref * (float(val_adc) / 1023);
  Serial.print(i);
  Serial.print(": adc reads ");
  Serial.print(val_adc);
  Serial.print(" counts = ");
  Serial.print(val_volts);
  Serial.println(" volts.");
  i++;
  if (i >= 10) {
    i = 0;
  }
}

quick link dump

Some interesting links I’ve known about…

arduino tagged items in makezine blog

related projects: processing, wiring, fritzing

lightning detector

I had the idea (during the recent lightning storms) to record the rate of lightning strikes.  There were a couple of ways to do it, I think

  • detect the radio from the lightning.  Might be able to get the direction with this, if the adc is fast enough.
  • just us a mic to pick up the thunder

I would like to keep the logs, so it would also require sending the data back to the computer.  One of the things that I think is pretty neat is that I can keep the program and hardware in a little box, then when the storm comes, load it onto the board, hook up the detectors, and be logging stuff.  Someday I may have two arduino boards and can dispense with that kind of nonsense!

[later edit] Popov invented an early radio, which he later developed into a lightening detection system (according to wikipedia).  I think he used a coherer (how to make) to do it, so I might try and do the same thing.  A coherer is impressively easy to make, but the unlatching system is a bit harder.  Either way, it shouldn’t be too hard to build.

comparisons

Well, I don’t know that much c++, the last time I worked with it was over a decade ago.  So, I’m not to surprised that I get an error like this:

In function ‘void loop()’:
error: ISO C++ forbids comparison between pointer and integer

I’m trying to print my string one character at a time, and do a new line when the end of the string is hit.  Only there isn’t any easy way to find out how long an array is (that I’ve found) in this version of c++.  Eventually this will blink out morse code stuff.  As usual, I think I’m tackling the hard and lame stuff first.

/* 
   a morse code translater
   
*/

char* myStr[] = {"some string"};

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

void loop() {
  boolean isChar = true;
  int i = 0;
  while (isChar) {
    char this_char = myStr[0][i];
    if (this_char != "") {
      Serial.print(this_char);
      Serial.println(i);
      delay(300);
    }
    else
    {
      delay(1000);
      Serial.println(" ");
      isChar = false;
    }
  }
}

/*
void look_up_morse(char letter) {
  // a dash is equal to three dots
  // the space between pars of the same letter is equal to one dot
  // the space between two letters is equal to three dots
  // the space between two words is equal to seven dots
  // pause = 0 (same length as a dot)
  // short = 1 (dot)
  // long  = 2 (dash, same length as three dots)
  
  // ascii notes:
  // capitol letters are 65 (A) to 90 (Z)
  // digits are 48 (0) to 57 (9)
  A = {1, 2};
  B = {2, 1, 1, 1};
  C = {2, 1, 2, 1};
  D = {2, 1, 1};
  E = {1};
  F = {1, 1, 2, 1};
  G = {2, 2, 1};
  H = {1, 1, 1, 1};
  I = {1, 1};
  J = {1, 2, 2, 2};
  K = {2, 1, 2};
  L = {1, 2, 1, 1};
  M = {2, 2};
  N = {2, 1};
  O = {2, 2, 2};
  P = {1, 2, 2, 1};
  Q = {2, 2, 1, 2};
  R = {1, 2, 1};
  S = {1, 1, 1};
  T = {2};
  U = {1, 1, 2};
  V = {1, 1, 1, 2};
  W = {1, 2, 2};
  X = {2, 1, 1, 2};
  Y = {2, 1, 2, 2};
  Z = {2, 2, 1, 1};
  one = {1, 2, 2, 2, 2};
  two = {1, 1, 2, 2, 2};
  three = {1, 1, 1, 2, 2};
  four = {1, 1, 1, 1, 2};
  five = {1, 1, 1, 1, 1};
  size = {2, 1, 1, 1, 1};
  seven = {2, 2, 1, 1, 1};
  eight = {2, 2, 2, 1, 1};
  nine  = {2, 2, 2, 2, 1};
  zero  = {2, 2, 2, 2, 2}; 
}
*/

terminal!

It turns out that having your code output stuff to a terminal is incredibly simple.  The code below will send the strings “str1″ etcetera out to the serial terminal, which is displayed in the little box at the bottom of the Arduino development environment.  Simply press the “serial monitor” button at the top of the ide, and you will see whatever you told the arduino board to print!

/* 
   a terminal printer
   
*/

char* mystr[] = { "str1", "str2", "str3", "str4", "str5", "str6"};

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

void loop() {
  for (int i = 0; i<6; i++) {
    Serial.println(mystr[i]);
    delay(500);
  }
}

terminal?

I would like to be able to see what my code is doing.  If it could print out to the terminal, that would great.  Is there a terminal environment for the arduino?  I guess what I really want is an emulator so that I can test my code and see what it is doing.  I don’t particularly want to write it in perl or python, then rewrite it in arduino language.  If I have to for debugging purposes, I guess I will.

another blinky interaction

I’ve got another idea for how the blinking can work.  It would be user specific, thought it might not be that different between users.  A “reader”, a person who wants to read the numbers from the thing, would calibrate the output to how long it takes them to count to 1o.  So they would press the start button, then count to 10, and the arduino would time that.  When it comes time to read out a number, the arduino would blink rapidly, and the person would count up.  so it would be <blinky-blinky>, and the person would be 1.. 2.. 3…  then it would stop blinking and the person would know that the number is supposed to be 3.

number blinker

A few things I’m trying to get right here:

  1. the number is correctly binked out.
  2. that it is easy/pleasant to read the number (requires timing of the blinks to be comfortable)
  3. works for an arbitrary number.

I went from the largest digit to the smallest.  I’m thinking I should probably do it the other way around, and go until I get a zero.  Here is my first go at the code.  It doesn’t blink out correctly- something is wrong at the 10′s place, it should blink 3 times, but instead only blinks twice (which is the ones value). I didn’t have time to do more.

/*
 * blinks out numbers
 * 
 *
 */

 int ledPin = 13;    // the LED pin (built in on my board)

 void setup() {
   pinMode(ledPin, OUTPUT);
 }

 void loop() {

   blinkStartup();

   delay(1000);

   int thisNum = 1332;  // the number to be blinked

   // this next bit is supposed to break it up into each digit
   // it doesn't work right now.

   int thousands = thisNum / 1000;
   int whatsLeft = thisNum % 1000;

   int hundreds  = whatsLeft / 100;
       whatsLeft = whatsLeft % hundreds;

   int tens = whatsLeft / 10;
   int ones = whatsLeft % 10;

   // blink it out part.

   blinkFast(3);
   delay(500);
   blinkSlow(thousands);

   delay(1000);

   blinkFast(2);
   delay(500);
   blinkSlow(hundreds);

   delay(1000);

   blinkFast(1);
   delay(500);
   blinkSlow(tens);

   delay(1000);
   blinkSlow(ones);

   delay(2000);

 }

 void blinkFast(int x) {
   for(int y=1;y<=x;y++) {
     digitalWrite(ledPin, HIGH);
     delay(50);
     digitalWrite(ledPin, LOW);
     delay(200);
   }
 }

 void blinkSlow(int x) {
   for(int y=1;y<=x;y++) {
     digitalWrite(ledPin, HIGH);
     delay(100);
     digitalWrite(ledPin, LOW);
     delay(200);
   }
 }

 void blinkStartup() {
   for(int i=0; i<10; i++){
     digitalWrite(ledPin,HIGH);
     delay(50);
     digitalWrite(ledPin,LOW);
     delay(50);
   }
 }

number blink out

Here is one idea for how to blink out numbers.

number blink out

the blips should actually be a full line high, the blinks are also a full line high.  The “end of number” indicator is only half height, I plan to use the PWM feature for that.

potential other projects: blinky

some further ideas:

  1. output primes (thanks Larne!)
  2. somehow output what the analog input is doing (it’s floating, so presumably doing something)
  3. morse code a message
  4. a fibonacci sequence blinker (but do base 10 blinks somehow, so we don’t have to count to 1000′s)
  5. base 10 counting trainer.  it blinks a sequence that is some number, so you can practice reading the blinks.
Follow

Get every new post delivered to your Inbox.