Arduino UNO
voltage divider (12V --> 3.72V)













Voltage divider

Vin = 15 V
R1 = 100 kohm
R2 = 33 kohm
Vout = 3.72V

(da http://www.lediouris.net/RaspberryPI/ADC/monitor-12v.html)


collegamenti

voltage divider rosso (+12V) --> ARDUINO PIN A0 ANALOG
voltage divider nero (GND)   --> ARDUINO PIN GND ANALOG

sketch Arduino (monitor12V)
================================================================
/*
DC Voltmeter 
*/
int analogInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 99400.0; // resistance of R1
float R2 = 33000.0; // resistance of R2
int value = 0;
void setup(){
   pinMode(analogInput, INPUT);
   Serial.begin(9600);
}
void loop(){
   // read the value at analog input
   value = analogRead(analogInput);
   vout = (value * 4.97) / 1024.0;
   vin = vout / (R2/(R1+R2)); 
   if (vin<0.09) {
   vin=0.0;
} 
Serial.println(vin);
delay(1000);
}
================================================================
Raspberry Pi Mod. B
ASUS USB-N13 wifi dongle
================================================================
python script Raspberry Pi (thingsspeak)

#!/usr/bin/env python

import serial
import time
import httplib,urllib

ser = serial.Serial("/dev/ttyAMA0", 9600)

while 1:
	volt=ser.readline()
	print volt

	params = urllib.urlencode({'field1': volt, 'key'XXXXXXXXXXXXXXXX'})	
	headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
    	conn = httplib.HTTPConnection("api.thingspeak.com :80")
    	conn.request("POST", "/update", params, headers)
    	response = conn.getresponse()
    	print response.status, response.reason
    	data = response.read()
    	conn.close()

	time.sleep(60) 	# frequenza 60 sec
================================================================

collegamento Arduino-Raspberry

rosso Arduino PIN 1 RX → Raspberry GPIO15 (UART0_RXD)
nero  Arduino PIN GND  → Raspberry GROUND

connessione al channel Thingspeak

Sistema di controllo remoto della batteria

Leave a Reply

Your email address will not be published. Required fields are marked *