Fév 282015
 

This is the last article about my water impulse counter project.
3 previous articles can be found here .

The last issue I encountered was about electro magnetic disturbances (probably my gaz heater nearby).
I initially planned to detect FALLING impulses (high to low, low meaning the reed switch is closed).
But about 4 times per hour, i detected a falling impulse, and this even the water circuit closed !

I therefore decided to review my code in the interrupt function now based on a CHANGE event (no more FALLING).


void IntChange() {
if (digitalRead(SWITCHPIN)==LOW) {
start=millis();
change=false;
} else {
if (start>0) {
pulse=millis()-start;
start=0;
change=true;
} else {
start=0;
change=false;
}//if (start>0)
} //if (digitalRead(SWITCHPIN)==LOW) {
}

And this proves to work perfectly now 🙂
See graph below.

The whole code can be found here.
it includes a web server (for my domotic box to query), a sd card reader (to store the counter value between power off), an interrupt handler.

Fév 212015
 

In previous article, my water pulse was settled in my garage.

Lets now design a wiring schema based on Arduino.
The idea is to use interrupts on the Arduino : it will be HIGH (i.e near 5V) always except and it will be LOW when the reed switch will be closed.
We then want to detect either when it is LOW, or FALLING, or CHANGE.
For now I’ll go for FALLING as this one is the easiest to implement.

rising-edgefalling-edge

 

We would then use something like the below :


//in the setup
attachInterrupt(1, CallBack, FALLING);

void CallBack(){
//the below check will software debounce our switch
if (millis()-last_water>500) {
last_water=millis();
water=water+1;
}
}

Next article will be about the code (a web server, logging to SD card, monitoring impulses …).

Fév 172015
 

For some years now I have monitoring and logging my energy consumption with an OWL 160.
Datas are then collected in a domotic box (a raspberry + jeedom)

Next step is now to do the same with water.
I have tried several solutions but came to the following conclusions :
-my counter needs to be located inside my house (as operating outside is not practical)
-i need to use a reliable solution like impulse

Therefore I bought the below product based on a reed switch : it will trigger an impulse for each liter.

Jan 302015
 

In some specific situations, you may want to backup only one partition but still wish to boot it as a disk image.
Lets see below how to turn a partition image into a disk image.

Before we start, have a a look at the below disk layout to have a better understanding of items such as MBR, BS, Disk and Partition.

1.Create a 1 MBytes (2048*512=1MB) header file (under virtualdisk, create raw disk image)
Note : instead of 2048 sectors, you can go for 63 or 128 or whatever « sectors before » may suit you – just report that number in the following steps.

2.Append this header to your partition image using the dos command line copy /b header.img+part.img disk.img

3.Adapt MBR type=07 (for ntfs), boot=80, chs start & end=1023*254*63, sectors before=2048, sectors=bootsector.totalsec+1
(You need to untick « hide advanced menu » under tools menu to enable advanced screens in CloneDisk).

4.Inject boot code (nt6) (this will also fix the mbr magic byte AA55).

5.Adapt bootSector hiddensec=2048 so that it matches MBR sectors before field

You are now ready to boot this image as it has all it requires to boot :
-a disk boot record
-a partition table
-a boot sector
-a consistent BPB (bios parameter block)

 Posted by at 19 h 05 min
Jan 242015
 

Lets start with a definition of the MBR :
A Master Boot Record (MBR) is a special type of boot sector at the very beginning of partitioned computer
mass storage devices. The MBR holds the information on how the logical partitions, containing file
systems, are organized on that medium.
Besides that, the MBR contains executable code to function as an operating system-independent chain boot loader in conjunction with each partition’s Volume Boot Record.

To make simpler, if a disk is a book, the mbr is the index table to quickly jump to each partitions.
MBR and GPT are just 2 different ways of writing that index (GPT handles a higher number of partitions and also bigger partitions).

So how to convert a GPT disk to MBR?

1.Write down the offset and length of your partition(s)

2.Delete the disk layout (this will not delete any datas, « only » the partition table and boot loader if any)

3.Create Disk (MBR style)


4.Create partition(s) with correct offset (most important) and length. Note that you can always correct these later by editing the MBR (advanced tools).
Choose IFS for a NTFS filesystem, or FAT32.


You end up with a MBR disk with a partition table similar to the GPT you previously had.
Note that you may want to inject a boot loader (nt6, g4d, etc) if this disk is a boot system one.
Also, this operation works the other way : MBR to GPT.

 Posted by at 19 h 20 min
Déc 242014
 

In a previous article, I have use an attiny85 + ds18b20 + rf433 to built a cheap temperature probe.

This time, I needed the humidity next to the temperature.
I then decided to use a dht11 (you can get it starting at 1.50€ on ebay).
Total cost is below 4€.

Here below the wiring.

tx_dht11_bb

Here rf433_sendOOK_at85_dht11 the arduino sketch (rename the txt file to ino).
You will also need this dht11 library.

Here some pictures. Notice that i used an old (but still good for my purpose) smartphone 3.7v battery.

IMG_4868

IMG_4865

IMG_4864

Nov 092014
 

I found a small microphone unused in some old box.
I decided I could play with it by plugging it to my arduino.
Was rather easy using the analogread function but it was lacking sensitivity.

Googling around it appeared I needed an op-amp. For less than 2 euros, I could get a 10 pieces batch on ebay.

See below the schematic.
Notice the voltage divider (r3 to 5v, r2 to gnd) to get a 2.5v voltage (5v / 2) : this way, you should read about 512 (1024 / 2) on the analog port when the microphone is off.
Notice the gain as well (r5/r4) which should give me about x75 gain (r5/r4*vin).

lm358_2

The Arduino sketch is rather simple : it will trigger a led when the reading goes about a certain value (that will depend on your mic and r0).

const int analogInPin = A0;  
const int ledPin=13;
int sensorValue = 0;        

void setup() {
  Serial.begin(38400); 
  pinMode(ledPin, OUTPUT); 
}

void loop() {
  digitalWrite(ledPin, LOW);
  sensorValue = analogRead(analogInPin);            
  if (sensorValue>640 || sensorValue<580) {
  Serial.print("sensor = " );                       
  Serial.println(sensorValue);   
  digitalWrite(ledPin, HIGH);  
  delay(50);
  }
  delay(50);                     
}
 Posted by at 16 h 56 min  Tagged with:
Oct 182014
 

In a previous article, we had use an Arduino + RF433 chip + DS28B20 to come up with a cheap temperature sensor.

We are going to improve the setup by replacing the Arduino Pro mini by an ATTINY85.
See here on how to flash an ATTINY85.

See rf433_sendOOK_at85 for the code.

Note that power consumption will be as low as 0.005ma (5ua) with a peak at 18ma when reading temp.

See below a revised wiring replacing the Arduino by an ATTINY85.

tx_ds18b20_v3_bb

 

 Posted by at 17 h 42 min
Oct 182014
 

In previous article, I made a cheap temperature probe using an arduino pro mini.

Still, the arduino pro mini is a bit overkill and i would like to keep it for prototyping my projects, not on « live » projects.

So lets have a look at the attiny85 :
-it is cheap (1€ a piece)
-runs at 8mhz
-has 8k programmable memory
-has very low power consumption

Sounds perfect for my needs !

Lets have a look at the pinout.

attiny45_85pinout

To flash this baby, I decided to use my arduino uno r3.
See below a quick how to.

1- unzip attiny under Documents\Arduino\hardware (you should end up with a folder attiny in there)
2- start the arduino ide and upload the arduinoisp sketch (in the arduino examples) to your « arduino uno r3 » board
3- choose « arduino as isp » under tools\programmer menu
4- choose « attiny85 (8mhz) » under tools\board
5- upload your sketch onto the attiny85

Lets see how to wire our attiny85 to your arduino.

flash_attiny85_bb

In a next article, we will see how to adapt this article for attiny85.

Hint : if you are getting the error « relocation truncated to fit », have a look here (and see to replace your ld.exe).

 Posted by at 13 h 46 min