Testing TM1638 + Go-Kart dashboard project

Hello world!

Well… Since my go-kart engine still in maintenance, I found another way to play with TM1638 display that I bought here: http://dx.com/p/8x-digital-tube-8x-key-8x-double-color-led-module-81873

Basically it read the values from the potentiometer and maps to 1 to 10000, more or less the rpm of the engine, and shows at display. Also turns on the leds mapping the value of the potentiometer from 1 to 16.

The small piece of code I wrote to do it is here:

#include <TM1638.h>

TM1638 module(8, 9, 7);
int potpin = 0;
int val;
int val2;
void setup(){}

void loop()
{
val = analogRead(potpin);
val2 = map(val, 0, 1023, 1, 16);
val = map(val, 0, 1023, 0, 10000);

switch (val2) {
case 1:
module.setLEDs(0x1);
break;
case 2:
module.setLEDs(0x3);
break;
case 3:
module.setLEDs(0x7);
break;
case 4:
module.setLEDs(0xF);
break;
case 5:
module.setLEDs(0x1F);
break;
case 6:
module.setLEDs(0x3F);
break;
case 7:
module.setLEDs(0x7F);
break;
case 8:
module.setLEDs(0xFF);
break;
case 9:
module.setLEDs(0x100);
break;
case 10:
module.setLEDs(0x300);
break;
case 11:
module.setLEDs(0x700);
break;
case 12:
module.setLEDs(0xF00);
break;
case 13:
module.setLEDs(0x1F00);
break;
case 14:
module.setLEDs(0x3F00);
break;
case 15:
module.setLEDs(0x7F00);
break;
case 16:
module.setLEDs(0xFF00);
break;
}
module.setDisplayToDecNumber(val,0,false);
delay(1);
}

More detailed information about how to use the TM1638 you can find here:

http://tronixstuff.wordpress.com/2012/03/11/arduino-and-tm1638-led-display-modules/

Also from this link above comes my inspiration to the dashboard I’m planning to do for my go-kart, this video:

More information about this project you can find here:

http://fergotech.net/diy-shift-lights-and-dashboard/

That’s why I bought magnetic switches… The idea is that one of this goes to rear axle, and each time ir switch from 0 to 1, Arduino reads it, calculate the time needed to turn one time and convert to km/h, according to the tire circumference.

Same for the RPM, each turn of the engine is has X milliseconds, based on that it’s possible to calculate how much rotations per minute it represents.

On both cases it’ll be used Arduino’s millis() function. Maybe for RPM I’ll need micros() instead, but I’m not sure yet. According to my calculations, millis() could not be so precise for this case… But I’ll need to test, and for sure I’ll post it here.

Have fun!

Temperature Sensor

Hello again, world!

Temperature is also important for my go-kart project (later I’ll write about the project itself). It’s pretty important to know how to change the fuel mixture to avoid doing a hole in the piston and screwing up the spark.

Considering that I bought a temperature sensor in DX and here it is:

IMG_0631[1]http://dx.com/p/diy-lm35-linear-temperature-sensor-module-black-166653

I put my finger close to it, so you can see how small it is. It uses the LM35 sensor, and here you can find its data sheet.

It works more or less like a potentiometer. You put on it 5v (or 3.3v, but you should change the code), and the output is mV, so we need analog pin. This sensor has a precision of 10mV/C, so for each Celsius degree output increase/decrease 10mV. And for each mV… you can do the math, right? 🙂

Arduino ADC has a precision of 10 bits or 5v / 1024 or ~0.0049. If we read the pin, we’ll have the value in volts, to convert it to millivolts we must multiply by 1000 and how the sensor precision is 10mV/C we must divide by 10… in other words “pin * 0.0049 * 1000 / 100”. Or being less stupid “pin * 0.49” and to convert to Fahrenheit multiply by 1.8 and then sum 32.

The left pin has a “-” close to it, what makes me know it’s the ground pin, the right one has a S close to it and I guess it is the output pin (if someone knows what “S” means, please let me know). The pin in the middle could only be VCC. Well… Now it’s easy to wire it… Left pin to Arduino ground pin, middle pin to Arduino 5v pin and right pin to Arduino A0 pin.

I wrote a small code to read the temperature:

int analogPin = 0;
int readValue = 0;
float temperature = 0;

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

void loop() {
readValue = analogRead(analogPin);
temperature = (readValue * 0.49);
Serial.print(“Temperature: “);
Serial.print(temperature);
Serial.print(” C “);
Serial.print((temperature * 1.8) + 32);
Serial.println(” F”);
delay(1000);
}

The output is:

Output from Temperature sensor

The value grows when you put the finger in the sensor, as you may notice in the picture above.

Have fun!!

Magnetic Detection Sensor Module

Hello world!

Some words about my tests with sensors I bought to go-kart project…

All of them work basically in the same way, you must connect VCC pin to Arduino 5v pin, G pin (or ground, or “-“) to Arduino groud pin and Out pin (or whatever its named) to some digital pin, in this example I used pin 2. When it detects a magnetic field (like a magnet) they change the status from 0 to 1, or from open to closed, or from LOW to HIGH… Whatever you need! Using digitalRead() function in Arduino is pretty easy to use them.

There’s one and a half exception only: The real exception is the last one (right side) in the picture below changes from 1 to 0 instead. For sure this is not a problem, you must just remember it when you’re writing your code. The “half” exception is the first one (left side) that looks to have also an analog output, I didn’t even tested it or Googled to know how it works… And I’m not planning to do it so soon…

.IMG_0630[1]

By now I tested them with a pretty small rare-earth magnet I found at home. The better one in my opinion is the red one in the right. It detected the magnet more or less from 1,5 cm and the others about 1 cm. I hoping to have better values with bigger magnet, otherwise I’m in a bad shape for what I’m planning to do.

To test it I wrote this small code that turns on the led at port 13. (or turn it of, in the case of right one).

int magnet = 2;
int led = 13;

void setup() {
pinMode(led, OUTPUT);
pinMode(magnet, INPUT);
digitalWrite(led, LOW);
}

void loop() {
int magnetState = digitalRead(magnet);
if (magnetState) {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led, LOW);
}
delay(1);
}

Easy, isn’t it? You can replace digitalWrite(led, HIGH) or digitalWrite(led, LOW) for whatever you want to do when it detects the magnetic field.

DX links to the magnetic sensors (in the order of the picture):

Btw… I also tested a Funduino Uno that I bought, since DX is not selling Arduino (I know it was fake) anymore. So far now it seems to work as an Arduino Uno!